package com.shiwaixiangcun.customer.presenter.impl;

import android.content.Context;
import android.widget.Toast;

import com.shiwaixiangcun.customer.GlobalApi;
import com.shiwaixiangcun.customer.entity.MerchDetailBean;
import com.shiwaixiangcun.customer.network.HttpCallBack;
import com.shiwaixiangcun.customer.network.HttpRequest;
import com.shiwaixiangcun.customer.presenter.ISurroundDetailPresenter;
import com.shiwaixiangcun.customer.ui.ISurroundDetailView;
import com.shiwaixiangcun.customer.utils.JsonUtil;

import java.util.HashMap;

/**
 *
 * @author Administrator
 * @date 2017/5/25
 */

public class SurroundDetailImpl implements ISurroundDetailPresenter {
    private ISurroundDetailView iSurroundDetailView;


    public SurroundDetailImpl(ISurroundDetailView iSurroundDetailView) {
        this.iSurroundDetailView = iSurroundDetailView;

    }

    @Override
    public void setBgaAdpaterAndClick(Context context,String merchId) {
        sendGetRentHttp(context,merchId);
    }


    /**
     * 获取商户详情
     *
     * @param context
     * @param merchId
     */
    private void sendGetRentHttp(final Context context,String merchId) {
        HashMap<String, Object> hashMap = new HashMap<>(2);
        hashMap.put("id", merchId);
        HttpRequest.get(GlobalApi.INSTANCE.getMerchantDetail(), hashMap, new HttpCallBack() {


            @Override
            public void onSuccess(String responseJson) {

                MerchDetailBean merchDetailBean = JsonUtil.fromJson(responseJson, MerchDetailBean.class);
                if (merchDetailBean == null) {
                    return;
                }
                if (merchDetailBean.getResponseCode() == 1001) {
                    iSurroundDetailView.setDataResponse(merchDetailBean);
                }else {
                    Toast.makeText(context,merchDetailBean.getMessage(),Toast.LENGTH_LONG).show();
                }


            }

            @Override
            public void onFailed(Exception e) {
                Toast.makeText(context,"网络异常，请稍后再试...",Toast.LENGTH_LONG).show();

            }
        });
    }


}
